<template>
	<div class="w-h-100">
		<el-row :gutter="8" style="width: 100%; height: 100%">
			<el-col :span="6" :xs="24" style="width: 100%; height: 100%">
				<form-component ref="formRef" @submit="(param: any) => submitHandle(param)"> </form-component>
			</el-col>
		</el-row>
	</div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { formComponent } from '/@/components/ys/index';
import { passwordConfig } from './config/index';
import cache from '/@/utils/hook/cache';
import { postChangePassword } from '/@/api/platformWork/index';
import { ElMessage } from 'element-plus';
import useCurrentInstance from '/@/utils/hook/useCurrentInstance';
const { proxy } = useCurrentInstance();
const $t = proxy.$t;

const formRef = ref();
const showData = async () => {
	let list: any = passwordConfig({});
	formRef.value.openDialog(list, '');
};
onMounted(() => {
	showData();
});
const submitHandle = async (param: any) => {
	if (param.oldPassword == param.newPassword) {
		ElMessage({
			message: $t('gb8DlV0Li4XlWb2R9evkT'),
			type: 'warning',
		});
		return;
	} else if (param.newPassword != param.makePassword) {
		ElMessage({
			message: $t('kbb2xcOWyftNfleA0Joh'),
			type: 'warning',
		});
		return;
	}

	const postData = {
		id: cache.getCache('userInfo').id,
		Account: cache.getCache('userInfo').staffName,
		Password: param.oldPassword,
		modifyPwd: param.newPassword,
		sureModifyPwd: param.makePassword,
	};

	const res = await postChangePassword(postData);
	if (res) {
		ElMessage.success($t('skBFcxsY120RbUcRvCFn6'));
		showData();
	}
	
};
</script>

<!-- scoped属性使style有自己独立的作用域(属性选择器实现 title[data-v-xxx]) -->
<style scoped></style>
